<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>引用类型</title>
</head>
<body>
    <!-- js中函数里面可以嵌入一个函数 -->
    <script>
        var f1 = new Function("a","b","console.log(a+b);");
        f1(2,3);
        var num = 100;
        var fun1 = function(){
            console.log(num);
            var num2 = 200;
        }
        fun1();
        // console.log(num2);报错 

        for(var i=1;i<=10;i++){
            console.log(i);
        }
        console.log(i)//函数外 打印出了11
        
        var fun3 = function () {
            var num = 100;
        }
        var fun4 = fun3;
        console.log(fun3 == fun4,fun3 === fun4);// ==判断值 ===先判断类型一致 再判断值


        //计数器困境
        function fun(){
            var num = 0; //设置计数器的初始值
            function fun1(){//闭包
                num++; 
                console.log('被调用了'+num+'次');
            };
            setInterval(fun1,1000);//每隔1s增加1
        };
        fun();
    </script>
</body>
</html>